<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>后台管理---导航菜单管理</title>
	<link rel="stylesheet" type="text/css" href="<?php echo base_url() ;?><?php echo APPPATH ;?>/views/<?php echo TEMPLETE_STYLE ;?>/easyui.css">
	<link rel="stylesheet" type="text/css" href="<?php echo base_url() ;?><?php echo APPPATH ;?>/views/<?php echo TEMPLETE_STYLE ;?>/admin.css">
	<link rel="stylesheet" type="text/css" href="<?php echo base_url() ;?><?php echo APPPATH ;?>/views/icon.css">
	<script type="text/javascript" src="<?php echo base_url() ;?><?php echo APPPATH ;?>/views/jquery-1.8.0.min.js"></script>
	<script type="text/javascript" src="<?php echo base_url() ;?><?php echo APPPATH ;?>/views/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="<?php echo base_url() ;?><?php echo APPPATH ;?>/views/common.js"></script>
</head>
<body>
	<h2>后台导航列表菜单</h2>
	<div class="demo-info">
		<div class="demo-tip icon-tip"></div>
		
		<div>注意：第三级是功能接点不会在菜单中显示的,如果是一级菜单请不要填写url地址</div>
	</div>
	<div style="margin:10px 0;">
		<a href="javascript:void(0)" class="easyui-linkbutton" onclick="edit()">Edit</a>
		<a href="javascript:void(0)" class="easyui-linkbutton" onclick="save()">Save</a>
		<a href="javascript:void(0)" class="easyui-linkbutton" onclick="cancel()">Cancel</a>
		<a id="add_" class="easyui-linkbutton l-btn" data-options="iconCls:'icon-add'" href="javascript:void(0)"  onclick="add_()"></a>
		<a  class="easyui-linkbutton" data-options="iconCls:'icon-remove'" href="javascript:void(0)"  onclick="remove_()"></a>
	</div>
	<table id="tg" class="easyui-treegrid" title="后台导航列表菜单" style="width:1050%;height:auto"
			data-options="
				iconCls: 'icon-ok',
				rownumbers: true,
				animate: true,
				collapsible: true,
				fitColumns: true,
				url: '<?php echo site_url('admin/nav_manager/index/show_nav');?>?action=ajax',
				method: 'get',
				idField: 'id',
				treeField: 'name',
				showFooter: true,
				toolbar:'#tb' 
			">
		<thead>
			<tr>
			<th  data-options="field:'id',checkbox:true"> 导航ID</th>
				<th data-options="field:'name',width:180,editor:'text'">导航名称</th>
				
				<th data-options="field:'status',width:80,editor:'numberbox'">状态</th>	
				<th data-options="field:'url',width:180,editor:'text'">url地址</th>		
				<th data-options="field:'disorder',width:80,editor:'numberbox',align:'center'">排序</th>		
				<th data-options="field:'addtime',width:120">添加日期</th>
				
				<!-- 
				<th data-options="field:'end',width:80,editor:'datebox'">End Date</th>
				<th data-options="field:'progress',width:120,formatter:formatProgress,editor:'numberbox'">Progress</th>
				 -->
			</tr>
		</thead>
	</table>
	<script type="text/javascript">
		$(function(){
			
			add_();
			$('#add_').click(function() {
                $('#w').window('open');
            });
			$('#btnCancel').click(function(){closeAdd();})
		});
		var editingId;
		function edit(){
			var row = $('#tg').treegrid('getSelected');			
			if (row){
				editingId = row.id ;			
				$('#edit_nav').window('open');
				var loadurl = "<?php echo site_url('admin/nav_manager/index/editnav') ;?>";
				loadurl=loadurl+"?id="+editingId;
				$('#ff_edit').form('load', loadurl);		//加载服务器上面的数据		
			}else{
				msgShow("系统警告","请选择进行编辑","error");
			}
		}
		function save(){
			if (editingId != undefined){
				var t = $('#tg');
				t.treegrid('endEdit', editingId);
				editingId = undefined;				
				var rows = t.treegrid('getSelected');
				var data_ = {
					"id":rows.id,
					"name":rows.name,
					"status":rows.status,
					"url":rows.url,
					"disorder":rows.disorder
				};
				
				$.ajax({
				   type: "POST",
				   url: "<?php echo site_url('admin/nav_manager/index/editnav');?>" ,
				   data: data_,
				   cache:false,
				   dataType:"json",
				 //  async:false,
				   success: function(msg){
					
					var code = msg.resultcode ;
					if(code <0){
						//window.location.href="<?php echo site_url('admin/login/jump_permition_html');?>" ;
						//return false ;
						msgShow("系统警告","对不起没有权限执行此操作,请联系管理员","error");
						return ; 
					}else if(code == 0 ){
						msgShow("系统警告",msg.resultinfo.errmsg,"error");
						return ;
					}else{
						$('#tg').treegrid();
					}		
				   },
				   
				   error:function(){
					   alert('服务器繁忙,请稍候....');
				   }
				  
				});					
		}
		}
		function cancel(){
			if (editingId != undefined){
				$('#tg').treegrid('cancelEdit', editingId);
				editingId = undefined;
			}
		}
	function remove_(){
		
		var tt = $('#tg').datagrid('getSelected');		
		if(!tt){
			msgShow("系统警告","请选择进行删除","error");
		}
	$.ajax({
		   type: "POST",
		   url: "<?php echo site_url('admin/nav_manager/index/deletenav');?>" ,
		   data: "id="+tt.id,
		   cache:false,
		   dataType:"json",
		 //  async:false,
		   success: function(msg){
			
			var code = msg.resultcode ;
			if(code <0){
				window.location.href="<?php echo site_url('admin/login/jump_permition_html');?>" ;
				return false ;
			}else if(code == 0 ){
				msgShow("系统警告",msg.resultinfo.errmsg,"error");
				return ;
			}else{
				$('#tg').treegrid();
			}		
		   },
		   
		   error:function(){
			   alert('服务器繁忙,请稍候....');
		   }
		  
		});			
	}
	
	function add_(){
            $('#w').window({
                title: '修改密码',
                width: 300,
                modal: true,
                shadow: true,
                closed: true,
                height: 250,
                resizable:false
            });	
		var tt = $('#tg').datagrid('getSelected');		
		if(tt){
			$("#pid").html("<option value="+tt.id+">"+tt.name+"</option>");
			
		}
		
	}
function closeAdd(){
	$('#w').window('close');
}
/*
	处理添加的数据
*/
function submitForm(){
			
			$('#ff').form('submit', {   
				url:'<?php echo site_url('admin/nav_manager/index/addnav') ;?>', 			
			    onSubmit: function(){   
					var isValid = $(this).form('validate');    
					return isValid ;
			    },   
			    success:function(data){  
			    	var data = $.parseJSON(data);
			    	
			    	if(data.resultcode == 0){
			    		msgShow("系统警告",data.resultinfo.errmsg,"error");
			    		return '' ;
				    }else if(data.resultcode>0){
						
						closeAdd();
						$('#tg').treegrid();
					}else{
						
						msgShow("系统信息",data.resultinfo.errmsg,"error");
						return ;
					}
			      
			    }
			    
			}); 				
}	
	
</script>

<div id="w" class="easyui-window" title="导航添加" collapsible="false" minimizable="false"
        maximizable="false" icon="icon-save"  style="width: 300px; height: 220px; padding: 5px;
        background: #fafafa;">
        <div class="easyui-layout" fit="true">
            <div region="center" border="false" style="padding: 10px; background: #fff; border: 1px solid #ccc;">
            <form id="ff" method="post" >
            	<input type="hidden" name="inajax" value="1">
                <table cellpadding=3>
                    <tr>
                        <td>所属分类:</td>
                        <td>
							<select name="pid" id="pid">
								<option value="0">顶层分类</option>
							</select>
						</td>
                    </tr>				
                    <tr>
                        <td>导航名称：</td>
                        <td><input class="easyui-validatebox"  id="nav_name" type="text" name="nav_name" data-options="required:true" validType="length[3,16]" missingMessage="导航不可以为空" invalidMessage="导航长度必须在6-16位之间"></input></td>
                    </tr>
                    <tr>
                        <td>url地址:</td>
                        <td><input class="easyui-validatebox"  id="url" type="text" name="url" data-options="required:true"  missingMessage="url地址不可以为空" invalidMessage="请输入url地址"></input></td>
                    </tr>
                    <tr>
                        <td>状态:</td>
                        <td>
						<select class="easyui-validatebox"  id='status' name="status" data-options="required:true" missingMessage="状态请选择" invalidMessage="状态请选择">
							<option value="">请选择</option>
							<option value="1">开启</option>
							<option value="0">关闭</option>
						</select>
						
                    </tr>	
                    <tr>
                        <td>排序:</td>
                        <td><input class="easyui-validatebox"  id="disorder" type="text" name="disorder" data-options="required:true"  missingMessage="请输入排序为整数" invalidMessage="请输入排序为整数"></input></td>
                    </tr>					
                </table>
                </form>
            </div>
            <div region="south" border="false" style="text-align: right; height: 30px; line-height: 24px; margin-top:4px">
                <a id="btnEp" class="easyui-linkbutton" icon="icon-ok" href="javascript:void(0)" onclick="submitForm()">
             			   确定
				</a> 
				<a id="btnCancel" class="easyui-linkbutton" icon="icon-cancel" href="javascript:void(0)">取消</a>
            </div>
        </div>
    </div>	
	



	
<!--编辑-->	
<div id="edit_nav" class="easyui-window" title="编辑导航" data-options="modal:true,closed:true,iconCls:'icon-save'" style="width:500px;height:260px;padding:10px;">
		   <div class="easyui-layout" fit="true">
            <div region="center" border="false" style="padding: 10px; background: #fff; border: 1px solid #ccc;">
            <form id="ff_edit" method="post" >
            	<input type="hidden" name="inajax" value="1">
                <table cellpadding=3>
                 			
                    <tr>
                        <td>导航名称：</td>
                        <td><input class="easyui-validatebox"  id="nav_name" type="text" name="name" data-options="required:true" validType="length[3,16]" missingMessage="导航不可以为空" invalidMessage="导航长度必须在6-16位之间"></input></td>
                    </tr>
                    <tr>
                        <td>url地址:</td>
                        <td><input class="easyui-validatebox"  id="url" type="text" name="url" data-options="required:true"  missingMessage="url地址不可以为空" invalidMessage="请输入url地址"></input></td>
                    </tr>
                    <tr>
                        <td>状态:</td>
                        <td>
						<select class="easyui-validatebox"  id='status' name="status" data-options="required:true" missingMessage="状态请选择" invalidMessage="状态请选择">
							<option value="">请选择</option>
							<option value="1">开启</option>
							<option value="0">关闭</option>
						</select>
						
                    </tr>	
                    <tr>
                        <td>排序:</td>
                        <td><input class="easyui-validatebox"  id="disorder" type="text" name="disorder" data-options="required:true"  missingMessage="请输入排序为整数" invalidMessage="请输入排序为整数"></input></td>
                    </tr>					
                </table>
                </form>
            </div>
            <div region="south" border="false" style="text-align: right; height: 30px; line-height: 24px; margin-top:4px">
                <a id="btnEp" class="easyui-linkbutton" icon="icon-ok" href="javascript:void(0)" onclick="submitForm()">
             			   确定
				</a> 
				<a id="btnCancel" class="easyui-linkbutton" icon="icon-cancel" href="javascript:void(0)" onclick="$('#edit_nav').window('close')">取消</a>
            </div>
        </div>
</div>
<!--编辑-->
</body>
</html>